%%% makeglo.sty -- A simple package for glossary generation.
%%% $Id: makeglo.sty,v 1.5 2000/05/07 23:09:37 jessen Exp $
%%%
%%% This package defines the commands \Glossary, \printglossary and
%%% the environments theglossary and glossdescription.  Must be used
%%% with the makeindex style file `makeglo.ist'.
%%%
%%% Written by Klaus Steding-Jessen <jessen@acm.org>
%%% This package is based on the nomencl package by Boris Veytsman
%%% <boris@plmsc.psu.edu>
%%%
%%% Usage:
%%%
%%% In the preable:
%%%   \usepackage{makeglo}
%%%   \renewcommand{\glossaryname}{Name of the Glossary}
%%%   \renewcommand{\glossmaxlabelwidth}{width} % optional
%%%   \makeglossary
%%%
%%%     Example:
%%%     \renewcommand{\glossaryname}{Glossary}
%%%     \renewcommand{\glossmaxlabelwidth}{\hspace{2cm}} or
%%%     \renewcommand{\glossmaxlabelwidth}{My longest entry}
%%%     \makeglossary
%%%
%%% In the document:
%%%   \Glossary[how_to_display_entry]{entry}{explanation}
%%%
%%%     Examples:
%%%     \Glossary{foo}{foo explanation}
%%%     \Glossary[$\alpha$]{alpha}{alpha explanation}
%%%
%%% In the document, where the glossary must be printed:
%%%   \clearpage
%%%   \printglossary
%%%
%%% Processing the document with latex and makeindex:
%%%   latex document
%%%   makeindex -s makeglo.ist -o document.gls document.glo
%%%   latex document

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{makeglo}
\RequirePackage{ifthen}

%%% Name of the Glossary.  You may change this in your document
%%% using, for example: \renewcommand{\glossaryname}{Definitions}
\newcommand{\glossaryname}{Glossary}

%%% Width of the entry column.  You may change this in your document
%%% using, for example:
%%% \renewcommand{\glossmaxlabelwidth}{\hspace{2cm}} or
%%% \renewcommand{\glossmaxlabelwidth}{My longest entry}
\newcommand{\glossmaxlabelwidth}{\hspace{1in}}

\newcommand{\glosspage}[1]{\relax}
\newcommand{\glossgroup}[1]{}
\newcommand{\glossprefix}{a}
\newcommand{\glossoutput}{}
\newlength{\glossentrylen}

\newenvironment{glossdescription}[1]%
{\list{}
  {\settowidth{\labelwidth}{\textbf{#1}}%
    \leftmargin\labelwidth\advance\leftmargin\labelsep%
    \renewcommand{\makelabel}[1]{%
      \settowidth{\glossentrylen}{\textbf{##1}}%
      \ifthenelse{\lengthtest{\glossentrylen > \labelwidth}}%
      {\parbox[b]{\labelwidth}%
        {\makebox[0pt][l]{\textbf{##1}}\\\mbox{}}}
      {\textbf{##1}}%
      \hfill\relax%
      }
}}
{\endlist}

\ifx\@undefined\chapter
\newenvironment{theglossary}{% article-like documents
  \section*{\glossaryname}\begin{glossdescription}{\glossmaxlabelwidth}}{%
  \end{glossdescription}}
\else
\newenvironment{theglossary}{% report/book-like documents
  \chapter*{\glossaryname}\begin{glossdescription}{\glossmaxlabelwidth}}{%
  \end{glossdescription}}
\fi

\newcommand{\Glossary}[3][]{%
  \ifthenelse{\equal{#1}{}}%
  {\renewcommand{\glossoutput}{#2}}%
  {\renewcommand{\glossoutput}{#1}}%
  \ignorespaces%
  \protected@write\@glossaryfile{}%
  {\string\glossaryentry{\glossprefix#2@[\glossoutput]#3%
      \protect|glosspage}{\thepage}}}

\newcommand{\printglossary}{%
  \InputIfFileExists{\jobname.gls}{}{\typeout{No file \jobname.gls}}}

%%% makeglo.sty ends here.
